package com.lj.luoye.lotteryticket.entity;

import com.lj.luoye.lotteryticket.util.AnalysisUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Unionlotto implements Comparable<Unionlotto> {
    public int id;
    public String date;
    public String description;
    public List<String> redBalls;
    public String blueBall;
    //复选
    public List<String> blueBalls;

    public int bought;
    public String luckResult;

    public Unionlotto() {
    }
    private List<String> sortRedBalls(List<String> redBalls){
        Collections.sort(redBalls);
        return redBalls;
    }
    public Unionlotto(int id, String date, String description, List<String> redBalls, String blueBall, int bought, String luckResult) {
        this.id = id;
        this.date = date;
        this.description = description;
        this.redBalls = sortRedBalls(redBalls);
        this.blueBall = blueBall;
        this.bought = bought;
        this.luckResult = luckResult;
    }
    public Unionlotto(int id, String date, String description, List<String> redBalls, List<String> blueBalls, int bought, String luckResult) {
        this.id = id;
        this.date = date;
        this.description = description;
        this.redBalls = sortRedBalls(redBalls);
        this.blueBalls = blueBalls;
        this.bought = bought;
        this.luckResult = luckResult;
    }

    public Unionlotto(int id, String date, String description, List<String> redBalls, String blueBall) {
        this.id = id;
        this.date = date;
        this.description = description;
        this.redBalls = sortRedBalls(redBalls);
        this.blueBall = blueBall;
    }

    public Unionlotto(int id, String date, String description, List<String> redBalls, List<String> blueBalls) {
        this.id = id;
        this.date = date;
        this.description = description;
        this.redBalls = sortRedBalls(redBalls);
        this.blueBalls = blueBalls;
    }

    public Unionlotto(String date, List<String> redBalls, String blueBall) {
        this.date = date;
        this.redBalls = sortRedBalls(redBalls);
        this.blueBall = blueBall;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<String> getRedBalls() {
        return redBalls;
    }

    public void setRedBalls(List<String> redBalls) {
        this.redBalls = redBalls;
    }

    public String getBlueBall() {
        return blueBall;
    }

    public void setBlueBall(String blueBall) {
        this.blueBall = blueBall;
    }

    public int getBought() {
        return bought;
    }

    public void setBought(int bought) {
        this.bought = bought;
    }

    public String getLuckResult() {
        return luckResult;
    }

    public void setLuckResult(String luckResult) {
        this.luckResult = luckResult;
    }

    @Override
    public String toString() {
        return "Unionlotto{" +
                "id=" + id +
                ", date='" + date + '\'' +
                ", description='" + description + '\'' +
                ", redBalls=" + redBalls +
                ", blueBall='" + blueBall + '\'' +
                ", bought=" + bought +
                ", luckResult='" + luckResult + '\'' +
                '}';
    }

    public String sprint(){
        String s="";
        for(String b:this.redBalls){
            s+=b;
        }
        s+="-"+this.blueBall;
        return s;
    }

    public List<Unionlotto> expand(){
        List<Unionlotto> unionlottoList=new ArrayList<>();
        //按红球展开
        int redBallCount=this.redBalls.size();
        List<List<Integer>> combines = AnalysisUtil.getCombines(redBallCount, 6);
        List<List<String>> redBallsCombines=new ArrayList<>();
        for(List<Integer> c:combines){
            List<String> redBallList=new ArrayList<>();
            for(int i:c){
                String s = this.redBalls.get(i);
                redBallList.add(s);
            }
            redBallsCombines.add(redBallList);
        }

        //按蓝球展开
        int blueBallCount=this.blueBalls.size();
        combines = AnalysisUtil.getCombines(blueBallCount, 1);
        List<List<String>> blueBallsCombines=new ArrayList<>();
        for(List<Integer> c:combines){
            List<String> blueBallList=new ArrayList<>();
            for(int i:c){
                String s = this.blueBalls.get(i);
                blueBallList.add(s);
            }
            blueBallsCombines.add(blueBallList);
        }

        //组合
        for(List<String> blues:blueBallsCombines){
            for(List<String> reds:redBallsCombines){
                unionlottoList.add(new Unionlotto(0,this.date,this.description, reds,blues.get(0)));
            }
        }

        return unionlottoList;
    }

    public int compareTo(Unionlotto o) {
        return this.getDate().compareTo(o.getDate())*(-1);
    }
}
